import React from 'react'
import { useRoutes, Navigate } from 'react-router-dom'
import LazyLoad from './utils/lazyLoad'
import Home from '@/pages/Home'
import Test from '@/pages/Test'
import Login from '@/pages/Login'
import { RouteObject } from './interface/index'

export const rootRouter: RouteObject[] = [
  {
    path: '/',
    element: <Navigate to="/home" />
  },
  {
    path: '/home',
    element: <Home />,
    meta: {
      title: '首页',
      requiresAuth: true,
      key: 'home'
    }
  },
  {
    path: '/test/:id/:name',
    element: <Test />,
    meta: {
      title: '测试',
      requiresAuth: true,
      key: 'test'
    }
  },
  {
    path: '/login',
    element: <Login />,
    meta: {
      title: '登录',
      requiresAuth: false,
      key: 'login'
    }
  },
  {
    path: '/404',
    element: LazyLoad(React.lazy(() => import('@/pages/404'))),
    meta: {
      title: '404页面',
      requiresAuth: false,
      key: '404'
    }
  },
  {
    path: '*',
    element: <Navigate to="/404" />
  }
]

export default () => useRoutes(rootRouter as any)
